﻿using System;
using Identity;

namespace Fee
{
    /// <summary>
    ///     站点
    /// </summary>
    public class Station
    {
        public static readonly DateTimeOffset Date2017 =
            new DateTimeOffset(new DateTime(2017, 1, 1), new TimeSpan(8, 0, 0));

        private StationStatus? _status;
        private string _thirdStationStatus;

        public int Id { get; set; }

        /// <summary>
        ///     站点服务区域
        /// </summary>
        public District District { get; set; }

        /// <summary>
        ///     站点提单区域
        /// </summary>
        public District OrderDistrict { get; set; }

        /// <summary>
        /// </summary>
        public string Code { get; set; }

        public StationType Type { get; set; }

       // public string ThirdPartyWorkOrderId { get; set; }
        /// <summary>
        ///     基站状态
        /// </summary>
        public StationStatus Status
        {
            get
            {
                if (_status == null)
                {
                    switch (ThirdStationStatus)
                    {
                        case "S1已完成":
                            _status = StationStatus.S1;
                            break;
                        case "S3已完成":
                            _status = StationStatus.S3;
                            break;
                        case "已投产":
                        case "投产报竣":
                        case "验收完成":
                       
                            _status = StationStatus.Complete;
                            break;
                        default:
                            _status = StationStatus.Unknown;
                            break;
                    }
                }

                return _status.Value;
            }
            protected set => _status = value;
        }

        public string ThirdStationStatus
        {
            get => _thirdStationStatus;
            set
            {
                _thirdStationStatus = value;
                switch (ThirdStationStatus)
                {
                    case "S1已完成":
                        _status = StationStatus.S1;
                        break;
                    case "S3已完成":
                        _status = StationStatus.S3;
                        break;
                    case "已投产":
                    case "投产报竣":
                    case "验收完成":
                        _status = StationStatus.Complete;
                        break;

                    default:
                        _status = StationStatus.Unknown;
                        break;
                }
            }
        }

        /// <summary>
        ///     同步时间
        /// </summary>
        public DateTimeOffset SyncTime { get; set; }

        /// <summary>
        ///     站点建设时间
        ///     主要用于 区别 2017 之前还是2017之后
        /// </summary>
        public DateTimeOffset? CreateTime { get; set; }

        /// <summary>
        ///     是否未重客户
        /// </summary>
        public bool IsVip { get; set; }

        /// <summary>
        ///     户数
        /// </summary>
        public int UsersNumber { get; set; }
        public string Name { get; set; }

        //  public ConstructionTask ConstructionTask { get; set; }

        /// <summary>
        /// </summary>
        /// <param name="time"></param>
        /// <returns></returns>
        public static bool IsBefore2017(DateTimeOffset? time)
        {
            if (time == null)
                return false;
            return time <= Date2017;
        }
    }
}